package com.erp.servlet;

import com.erp.bean.Department;
import com.erp.service.DepartmentService;
import com.erp.service.impl.DepartmentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author zch
 * 添加部门控制器
 */
@WebServlet("/adddept.action")
public class AdddeptServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        DepartmentService departmentService = new DepartmentServiceImpl();
        String deptname = req.getParameter("deptname");
        Department department = new Department(deptname);
        boolean flag = departmentService.add(department);
        System.out.println(flag);
        resp.sendRedirect("deptlist.action");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
